-- @owner: @zou_jialiang050
-- @date: 2022/02/24
-- @testpoint: 向src表中插入数据前，对每条语句触发向des表中插入数据触发器   des表中未插入数据

--step1:建表;expect:成功
drop table if exists t_trigger_src cascade;
drop table if exists t_trigger_des cascade;
create table t_trigger_src(id1 int, id2 int, id3 int) with (storage_type=ustore);
create table t_trigger_des(id1 int, id2 int, id3 int) with (storage_type=ustore);
--step2:向src表中插入数据前触发向des表中插入数据src表返回值 each statement;expect:成功，des表中无数据
create or replace function tri_insert_func() returns trigger as
$$
declare
begin
insert into t_trigger_des select * from t_trigger_src;
return new;
end
$$ language plpgsql;
/
drop trigger if exists insert_trigger on t_trigger_src cascade;
create trigger insert_trigger before insert on t_trigger_src
        for each statement
        execute procedure tri_insert_func();
/
select * from t_trigger_des;
insert into t_trigger_src values(2,2,2),(1,1,1);
select * from t_trigger_des;
--step3:环境清理;expect:成功
drop table if exists t_trigger_src cascade;
drop table if exists t_trigger_des cascade;